package gamepack;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;

import javax.sound.sampled.*;

class DataClip
{
    public byte[] data;
    public int index;
    public AudioFormat format;

    public boolean running = false;
    public int sampleRate;

    public DataClip(byte[] data, AudioFormat format)
    {
        this.data = data;
        this.index = 0;
        this.format = format;
    }

    public DataClip(AudioInputStream in) throws IOException
    {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int data;

        while((data = in.read()) >= 0) out.write(data);

        in.close();

        this.data = out.toByteArray();
        this.index = 0;
        this.format = in.getFormat();
    }

    public void calculateSampleRate(int milliseconds)
    {
        sampleRate = (int)((milliseconds*(format.getSampleRate()*format.getSampleSizeInBits()/8))/1000);
    }
}